/*
 * @Author: dadadaXU 1413107032@qq.com
 * @Date: 2025-02-23 17:30:58
 * @LastEditors: dadadaXU 1413107032@qq.com
 * @LastEditTime: 2025-02-23 17:41:52
 * @FilePath: \LeetCode\20.有效的括号.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @lc app=leetcode.cn id=20 lang=cpp
 *
 * [20] 有效的括号
 */

#include <string>
#include <stack>

// @lc code=start
class Solution
{
public:
    bool isValid(std::string s)
    {
        std::stack<char> bracketStack;
        for (auto c : s)
        {
            if (bracketStack.empty())
                bracketStack.push(c);
            else
            {
                if ((bracketStack.top() == '(' && c == ')') ||
                    (bracketStack.top() == '[' && c == ']') ||
                    (bracketStack.top() == '{' && c == '}'))
                    bracketStack.pop();
                else
                    bracketStack.push(c);
            }
        }

        return bracketStack.empty();
    }
};
// @lc code=end
